class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  belongs_to :creator, :class_name => 'User'

  #belongs_to :current_member, :class_name => 'Member', :foreign_key=>'current_member_id'
  
  #has_many :members, :class_name => 'Member', :dependent => :destroy
  #has_many :shares, :class_name => 'Share', :dependent => :destroy 

  #has_many :projects, through: :members
   scope :enabled_scope, -> { where(enabled: true) }

  #validates :email, presence: true , uniqueness: true

  validates :name, presence: true , uniqueness: true

  #validates_presence_of :name
  

  def self.not_belong_project project_id
      project = Project.find(project_id)
      users = User.joins("LEFT JOIN members ON users.id = members.id")
      users = users.where("users.id not in(select user_id from members where project_id = ?)",project_id)
      return users
  end

  # def can_upload folder
  #      return false unless folder
  #      return true if self.is_sys_admin
  #      if current_member && self.current_member.project_id == folder.project_id
  #         return true if current_member.is_project_admin
  #         return true if current_member.is_group_admin && folder.group_folders.exists(:group_id=>self.current_member.id)
  #      end
  #      return false
  # end

  # def can_read doc
  #   return false unless doc
  #   return true if self.is_sys_admin
  #   return true if doc.shares.exists?(:user_id=>self.id)
  #   if self.current_member && self.current_member.project_id == doc.project_id
  #     return true if self.current_member.is_project_admin
  #     return true if self.current_member.is_group_admin && doc.folder.group_folders.exists?(:group_id=>self.current_member.group_id)
  #   end
   

  #   return false

  # end

  # def can_share doc
  #   return false unless doc
  #   return true if self.is_sys_admin
  #   if self.current_member && self.current_member.project_id == doc.project_id
  #     return true if self.current_member.is_project_admin
  #     return true if self.current_member.is_group_admin && doc.folder.group_folders.exists?(:group_id=>self.current_member.group_id)
  #   end
  #   return false 
  # end

  before_destroy do |user|
      
  end

 


end
